Skip to content

[codex] Structure preview automation errors - #3272

Merged
juliusmarminge merged 4 commits into
mainfrom
codex/audit-preview-automation-errors
Jun 20, 2026
Merged

[codex] Structure preview automation errors#3272
juliusmarminge merged 4 commits into
mainfrom
codex/audit-preview-automation-errors

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary\n- attach MCP scope, provider, client, request, tab, timeout, and bounded selector context to preview automation failures\n- distinguish host, disconnect, queue, remote-unavailable, and malformed-response failures instead of collapsing them into message bags\n- retain remote tags plus message lengths/detail kinds without copying arbitrary remote messages, details, or selectors into direct fields/messages; preserve the exact remote failure payload only as the cause chain

Verification

  • vp test apps/server/src/mcp/PreviewAutomationBroker.test.ts
  • vp check (passes with 20 pre-existing warnings)
  • vp run typecheck

Note

Medium Risk
Broker and contract error shapes change in ways that break PreviewAutomationUnavailableError matching; behavior is still localized to preview automation/MCP paths with added tests.

Overview
Preview automation failures are now typed, request-scoped errors instead of free-form message bags.

Contract error classes gain MCP scope (operation, environmentId, threadId, providerSessionId, providerInstanceId) and, when a request was in flight, client/request context (clientId, requestId, tabId, timeoutMs). Remote failures add bounded diagnostics (remoteTag, remoteMessageLength, optional remoteDetailKind) and keep the wire payload on cause, without copying arbitrary remote messages or selector strings into surfaced fields. PreviewAutomationInvalidSelectorError drops the raw selector in favor of selectorKind / selectorLength.

PreviewAutomationBroker stores that context on each pending request, uses classifyResponseError to map remote tags (including legacy PreviewAutomationUnavailableError) to the right type, and splits former “unavailable” cases into PreviewAutomationHostNotConnectedError, PreviewAutomationClientDisconnectedError, PreviewAutomationRequestQueueClosedError, PreviewAutomationRemoteUnavailableError, and PreviewAutomationMalformedResponseError. Tests assert the new shapes and that secrets do not leak into message.

Breaking for callers: code that only matched PreviewAutomationUnavailableError from the broker must handle the new tags; the old class remains for other uses (e.g. MCP capability checks).

Reviewed by Cursor Bugbot for commit 9112391. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Structure preview automation errors with typed context and diagnostics

  • Replaces generic error construction in PreviewAutomationBroker with structured per-request context (PreviewAutomationRequestErrorContext) carrying operation, environment, thread, provider, client, request, timeout, and selector diagnostics.
  • Adds five new error types: PreviewAutomationHostNotConnectedError, PreviewAutomationClientDisconnectedError, PreviewAutomationRequestQueueClosedError, PreviewAutomationRemoteUnavailableError, and PreviewAutomationMalformedResponseError.
  • Existing errors (NoFocusedOwnerError, TimeoutError, ExecutionError, InvalidSelectorError, etc.) are extended with structured request/scope fields and dynamic message getters; raw selector values are replaced with bounded selectorKind/selectorLength diagnostics.
  • classifyResponseError replaces makeResponseError, mapping remote failures to concrete typed errors with remote tag, message length, and detail kind metadata.
  • Behavioral Change: PreviewAutomationUnavailableError from remote is now mapped to PreviewAutomationRemoteUnavailableError; client disconnection during a pending request now throws PreviewAutomationClientDisconnectedError instead of PreviewAutomationUnavailableError.

Macroscope summarized 9112391.

Co-authored-by: codex <codex@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8ec662f7-bcae-4fe5-b70f-c93be6f32690

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/audit-preview-automation-errors

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Jun 20, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Disconnect masked as queue closed
    • Used Deferred.poll when Queue.offer returns false to check if the deferred was already completed with PreviewAutomationClientDisconnectedError by disconnect(), falling back to PreviewAutomationRequestQueueClosedError only when the deferred is still pending.

Create PR

Or push these changes by commenting:

@cursor push e0c5ec88bf
Preview (e0c5ec88bf)
diff --git a/apps/server/src/mcp/PreviewAutomationBroker.ts b/apps/server/src/mcp/PreviewAutomationBroker.ts
--- a/apps/server/src/mcp/PreviewAutomationBroker.ts
+++ b/apps/server/src/mcp/PreviewAutomationBroker.ts
@@ -375,7 +375,11 @@
         timeoutMs,
       });
       if (!offered) {
-        return yield* new PreviewAutomationRequestQueueClosedError(requestContext);
+        const completed = yield* Deferred.poll(deferred);
+        return yield* Option.match(completed, {
+          onNone: () => Effect.fail(new PreviewAutomationRequestQueueClosedError(requestContext)),
+          onSome: (effect) => effect as Effect.Effect<A, PreviewAutomationError>,
+        });
       }
       const result = yield* Deferred.await(deferred).pipe(Effect.timeoutOption(timeoutMs));
       return yield* Option.match(result, {

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 472d593. Configure here.

Comment thread apps/server/src/mcp/PreviewAutomationBroker.ts
@macroscopeapp

macroscopeapp Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

This PR refactors preview automation error classes to include structured diagnostic fields instead of just message strings. The changes improve error observability without altering when or why errors are thrown, and comprehensive tests verify the new structure.

You can customize Macroscope's approvability policy. Learn more.

Co-authored-by: codex <codex@users.noreply.github.com>
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Jun 20, 2026
Co-authored-by: codex <codex@users.noreply.github.com>
@macroscopeapp
macroscopeapp Bot dismissed their stale review June 20, 2026 16:17

Dismissing prior approval to re-evaluate 195af59

Co-authored-by: codex <codex@users.noreply.github.com>
@juliusmarminge
juliusmarminge merged commit 336d176 into main Jun 20, 2026
16 checks passed
@juliusmarminge
juliusmarminge deleted the codex/audit-preview-automation-errors branch June 20, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant